package controller;

import model.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class RoomController {
    static Map<String, Room> rooms = new HashMap<>();//room_id,room
    static HashMap<CommonContent.DIRECTION, CommonContent.DIRECTION>oppositeDirection=new HashMap<>();
    public static void op(){
        oppositeDirection.put(CommonContent.DIRECTION.UP,CommonContent.DIRECTION.DOWN);
        oppositeDirection.put(CommonContent.DIRECTION.DOWN,CommonContent.DIRECTION.UP);
        oppositeDirection.put(CommonContent.DIRECTION.EAST,CommonContent.DIRECTION.WEST);
        oppositeDirection.put(CommonContent.DIRECTION.WEST,CommonContent.DIRECTION.EAST);
        oppositeDirection.put(CommonContent.DIRECTION.NORTH,CommonContent.DIRECTION.SOUTH);
        oppositeDirection.put(CommonContent.DIRECTION.SOUTH,CommonContent.DIRECTION.NORTH);
        oppositeDirection.put(CommonContent.DIRECTION.NORTHWEST,CommonContent.DIRECTION.SOUTHEAST);
        oppositeDirection.put(CommonContent.DIRECTION.SOUTHWEST,CommonContent.DIRECTION.NORTHEAST);
        oppositeDirection.put(CommonContent.DIRECTION.SOUTHEAST,CommonContent.DIRECTION.NORTHWEST);
        oppositeDirection.put(CommonContent.DIRECTION.NORTHEAST,CommonContent.DIRECTION.SOUTHWEST);
    }
    public static CommonContent.DIRECTION getop(CommonContent.DIRECTION direction) {
        return oppositeDirection.get(direction);
    }
    public static void createRooms() throws IOException {
        RoomController.op();
        Room room1 = new Room();
        room1.setRoomId("zhucheng");
        room1.SetRoomName("主城");
        room1.setDescription("这是主城。");
        Room room2 = new Room();
        room2.setRoomId("huiguanghuilang");
        room2.SetRoomName("辉光回廊");
        room2.setDescription("这里是学者和寻光者的圣地，但过度凝视镜中知识可能导致理性被辉光吞噬，化为“燃尽的灯芯”。");
        Room room3 = new Room();
        room3.setRoomId("rongzhuzhidu");
        room3.SetRoomName("熔铸之都");
        room3.setDescription("这是一座由活体金属构筑的蒸汽朋克城市，熔炉永不熄灭，建筑随司辰意志重组。");
        Room room4 = new Room();
        room4.setRoomId("tiejibilei");
        room4.SetRoomName("铁棘壁垒");
        room4.setDescription("这是一座环绕荆棘钢墙的军事要塞，空中悬浮着刀刃风暴，地面流淌着锈蚀血河。");
        Room room5 = new Room();
        room5.setRoomId("yongjixueyuan");
        room5.SetRoomName("永寂雪原");
        room5.setDescription("这里是时间停滞的极寒荒原，风雪中回荡着未安息的低语，冰层下冻结着被遗忘的历史。");
        Room room6 = new Room();
        room6.setRoomId("xinyuanhuixiang");
        room6.SetRoomName("心渊回响");
        room6.setDescription("一片由液态情感凝聚的琥珀色湖泊，湖面倒映众生记忆，湖底沉睡着扭曲的灵魂元素。");
        Room room7 = new Room();
        room7.setRoomId("yunianzhidian");
        room7.SetRoomName("欲念之殿");
        room7.setDescription("一座黄金与血肉交融的宫殿，空气中弥漫致幻香气，宴席永不散场。");
        Room room8 = new Room();
        room8.setRoomId("huantuizhisen");
        room8.SetRoomName("幻蜕之森");
        room8.setDescription("不断生长的黑色森林，树木形态随直觉扭曲，阴影中潜伏着蜕变未完成的生物。");
        Room room9 = new Room();
        room9.setRoomId("mishihuilang");
        room9.SetRoomName("秘史回廊");
        room9.setDescription("由破碎时空拼接的迷宫，墙壁刻满未被司辰承认的“非法历史”，裂隙中闪现其他历史的投影。");
        room1.setRoom(CommonContent.DIRECTION.NORTH,room2);
        room1.setRoom(CommonContent.DIRECTION.EAST,room4);
        room1.setRoom(CommonContent.DIRECTION.SOUTH,room6);
        room1.setRoom(CommonContent.DIRECTION.WEST,room8);
        room1.setRoom(CommonContent.DIRECTION.SOUTHWEST,room7);
        room1.setRoom(CommonContent.DIRECTION.SOUTHEAST,room5);
        room1.setRoom(CommonContent.DIRECTION.NORTHEAST,room3);
        room1.setRoom(CommonContent.DIRECTION.NORTHWEST,room9);
        room2.setRoom(CommonContent.DIRECTION.SOUTH,room1);
        room2.setRoom(CommonContent.DIRECTION.EAST,room3);
        room2.setRoom(CommonContent.DIRECTION.SOUTHWEST,room8);
        room2.setRoom(CommonContent.DIRECTION.SOUTHEAST,room4);
        room2.setRoom(CommonContent.DIRECTION.WEST,room9);
        room3.setRoom(CommonContent.DIRECTION.SOUTHWEST,room1);
        room3.setRoom(CommonContent.DIRECTION.WEST,room2);
        room3.setRoom(CommonContent.DIRECTION.SOUTH,room4);
        room4.setRoom(CommonContent.DIRECTION.SOUTH,room5);
        room4.setRoom(CommonContent.DIRECTION.SOUTHWEST,room6);
        room4.setRoom(CommonContent.DIRECTION.WEST,room1);
        room4.setRoom(CommonContent.DIRECTION.NORTHWEST,room2);
        room4.setRoom(CommonContent.DIRECTION.NORTH,room3);
        room5.setRoom(CommonContent.DIRECTION.NORTH,room4);
        room5.setRoom(CommonContent.DIRECTION.WEST,room6);
        room5.setRoom(CommonContent.DIRECTION.NORTHWEST,room1);
        room6.setRoom(CommonContent.DIRECTION.NORTH,room1);
        room6.setRoom(CommonContent.DIRECTION.EAST,room5);
        room6.setRoom(CommonContent.DIRECTION.NORTHEAST,room4);
        room6.setRoom(CommonContent.DIRECTION.NORTHWEST,room8);
        room6.setRoom(CommonContent.DIRECTION.WEST,room7);
        room7.setRoom(CommonContent.DIRECTION.NORTH,room8);
        room7.setRoom(CommonContent.DIRECTION.EAST,room6);
        room7.setRoom(CommonContent.DIRECTION.NORTHEAST,room1);
        room8.setRoom(CommonContent.DIRECTION.NORTHEAST,room2);
        room8.setRoom(CommonContent.DIRECTION.EAST,room1);
        room8.setRoom(CommonContent.DIRECTION.NORTH,room9);
        room8.setRoom(CommonContent.DIRECTION.SOUTHEAST,room6);
        room8.setRoom(CommonContent.DIRECTION.SOUTH,room7);
        room9.setRoom(CommonContent.DIRECTION.EAST,room2);
        room9.setRoom(CommonContent.DIRECTION.SOUTH,room8);
        room9.setRoom(CommonContent.DIRECTION.SOUTHEAST,room1);
        rooms.put(room1.getRoomId(), room1);
        rooms.put(room2.getRoomId(), room2);
        rooms.put(room3.getRoomId(), room3);
        rooms.put(room4.getRoomId(), room4);
        rooms.put(room5.getRoomId(), room5);
        rooms.put(room6.getRoomId(), room6);
        rooms.put(room7.getRoomId(), room7);
        rooms.put(room8.getRoomId(), room8);
        rooms.put(room9.getRoomId(), room9);
        createMonster();
        createNpc();
        ItemController.createItems();
    }
    public static void createNpc() throws IOException {
        Npc npc1=new Npc(100,100,100,100,500,500,300,300,300,300,"波比·拉舍莱斯",
                "zhucheng",
                "一个和蔼可亲的女人。",2);
        Npc npc2=new Npc(100,100,100,100,500,500,300,300,300,300,"挽歌儿小姐",
                "yongjixueyuan",
                "一幅画作，画中肤色深暗的女人拥有雪色的双眸和剪得很短的骨白色头发，站在一个长满白花藤的小型大理石墓前。",2);
        npcInit(npc1);
        npcInit(npc2);
    }
    public static void createMonster() throws IOException {
        Monster monster1 = new Monster(10, 10, 5, 10, 50, 50, 50, 50, 50, 50, "讨人厌的警探",
                "tiejibilei",
                3, "一个烦人的警探，是个凡人。");
        monsterInit(monster1);
    }

    private static void monsterInit(Monster monster) {
        getRoom(monster.getLocation()).mosterSet(monster);
    }

    private static void npcInit(Npc npc) throws IOException {
        getRoom(npc.getLocation()).NpcEnter(npc);
    }

    public static Room getRoom(String roomId) {
        return rooms.get(roomId);
    }
    public static void npcMove() throws IOException {
        for(Room r:rooms.values()){
            r.NpcMove();
        }
    }
    public static void monsterFlush() throws IOException {
        createMonster();
    }
}
